-- card: 3118 from stack: in.3 -- bmap block id: 0 -- flags: 4000 -- background id: 2663 -- name: Convert number to string ----- HyperTalk script ----- Function NumToString ThisWord -- String Convert, Copyright by Mac Help Co., January 1988 -- by Chris Hostetter, Mac Help Co., 1800 East Market Street -- Long Beach, CA 90805, (213) 428-7414 -- The script for this button is copyrighted and may not be -- used without the written permission of the author (above). put ThisWord into RememberWord put empty into Millions put empty into Thousands -- ADD THE WORD 'DOLLARS' (put false here to skip the word 'Dollars') put true into DollarPhrase -- ADD THE WORD 'CENTS' (put false here to skip the word 'Cents') put true into CentPhrase put 0 into dollars put 0 into cents put the length of ThisWord into StringLength repeat with i = 1 to stringLength if char i of ThisWord is "." then exit repeat put dollars & char i of ThisWord into dollars end repeat if i < StringLength then -- found a decimal point -- put char i+1 to StringLength of ThisWord into cents -- All places put char i+1 of ThisWord into cents -- Limit to 2 places if char i+2 of ThisWord is empty then put cents & "0" into cents else put cents & char i+2 of ThisWord into cents -- Limit to 2 places end if end if put the value of dollars into ThisWord put the length of ThisWord into stringLength if stringLength > 6 and stringLength < 10 then put ThisWord into RememberWord delete char Stringlength-6+1 to StringLength of ThisWord if the value of ThisWord is 0 then else put PartNumToString(ThisWord) & "Million " into Millions end if put char StringLength-6+1 to StringLength of RememberWord into ThisWord end if put the length of ThisWord into StringLength if stringLength > 3 and stringLength < 7 then put ThisWord into RememberWord delete char Stringlength-3+1 to StringLength of ThisWord if the value of ThisWord is 0 then else put PartNumToString(ThisWord) & "Thousand " into Thousands end if put char StringLength-3+1 to StringLength of RememberWord into ThisWord end if put the length of ThisWord into stringLength if stringLength < 4 then if dollarPhrase is true then -- ***** USE THIS LINE TO INCLUDE THE WORD 'DOLLARS' put Millions & Thousands & PartNumToString(ThisWord) & "DOLLARS" into Dollars else -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'DOLLARS' put Millions & Thousands & PartNumToString(ThisWord) into Dollars end if end if put PartNumToString(cents) into ThisWord if ThisWord is empty then put "Zero " into ThisWord if Dollars is "Dollars" then if centPhrase is true then -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS' put ThisWord & "CENTS" into ThisWord else -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS' put ThisWord into ThisWord end if else if centPhrase is true then -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS' put Dollars && "and" && ThisWord & "CENTS" into ThisWord else -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS' put Dollars && "and" && ThisWord into ThisWord end if end if Return ThisWord end NumToString Function PartNumToString String put empty into part put String into ThisWord if the length of thisWord is 3 then if the value of ThisWord is 0 then put empty into String Return String exit PartNumToString end if put first char of ThisWord into String if the value of String is not 0 then put GetOnes(String) & "Hundred " into part end if put char 2 to 3 of ThisWord into String end if if the value of String < 20 then put part & GetOnes(String) into String else if string is not empty then put the value of string into TensString if TensString is 0 then put empty into String if TensString > 19 then put "Twenty " into String if TensString > 29 then put "Thirty " into String if TensString > 39 then put "Forty " into String if TensString > 49 then put "Fifty " into String if TensString > 59 then put "Sixty " into String if TensString > 69 then put "Seventy " into String if TensString > 79 then put "Eighty " into String if TensString > 89 then put "Ninety " into String put part & String into Part end if put last char of ThisWord into String put part & GetOnes(String) into String end if Return String end PartNumToString Function GetOnes Ones if Ones is empty then exit GetOnes if the value of Ones is 0 then put empty into Ones else if Ones is 1 then put "One " into Ones else if Ones is 2 then put "Two " into Ones else if Ones is 3 then put "Three " into Ones else if Ones is 4 then put "Four " into Ones else if Ones is 5 then put "Five " into Ones else if Ones is 6 then put "Six " into Ones else if Ones is 7 then put "Seven " into Ones else if Ones is 8 then put "Eight " into Ones else if Ones is 9 then put "Nine " into Ones else if Ones is 10 then put "Ten " into Ones else if Ones is 11 then put "Eleven " into Ones else if Ones is 12 then put "Twelve " into Ones else if Ones is 13 then put "Thirteen " into Ones else if Ones is 14 then put "Fourteen " into Ones else if Ones is 15 then put "Fifteen " into Ones else if Ones is 16 then put "Sixteen " into Ones else if Ones is 17 then put "Seventeen " into Ones else if Ones is 18 then put "Eighteen " into Ones else if Ones is 19 then put "Nineteen " into Ones Return Ones end GetOnes -- part 1 (button) -- low flags: 00 -- high flags: 8003 -- rect: left=306 top=47 right=69 bottom=456 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Convert # to String ----- HyperTalk script ----- on copyright -- String Convert, Copyright by Mac Help Co., January 1988 -- by Chris Hostetter, Mac Help Co., 1800 East Market Street -- Long Beach, CA 90805, (213) 428-7414 -- The script for this button is copyrighted and may not be -- used without the written permission of the author (above). end copyright on mouseUp ask "Enter a number" put it into ThisNumber -- simply invoke the command 'NumToString(it)' and whatever is in it -- will be changed to a string ask it with NumToString(ThisNumber) put ThisNumber & ": " & NumToString(ThisNumber) into card field ID 2 end mouseUp Function NumToString ThisWord put ThisWord into RememberWord put empty into Millions put empty into Thousands -- ADD THE WORD 'DOLLARS' (put false here to skip the word 'Dollars') put true into DollarPhrase -- ADD THE WORD 'CENTS' (put false here to skip the word 'Cents') put true into CentPhrase put 0 into dollars put 0 into cents put the length of ThisWord into StringLength repeat with i = 1 to stringLength if char i of ThisWord is "." then exit repeat put dollars & char i of ThisWord into dollars end repeat if i < StringLength then -- found a decimal point -- put char i+1 to StringLength of ThisWord into cents -- All places put char i+1 of ThisWord into cents -- Limit to 2 places if char i+2 of ThisWord is empty then put cents & "0" into cents else put cents & char i+2 of ThisWord into cents -- Limit to 2 places end if end if put the value of dollars into ThisWord put the length of ThisWord into stringLength if stringLength > 6 and stringLength < 10 then put ThisWord into RememberWord delete char Stringlength-6+1 to StringLength of ThisWord if the value of ThisWord is 0 then else put PartNumToString(ThisWord) & "Million " into Millions end if put char StringLength-6+1 to StringLength of RememberWord into ThisWord end if put the length of ThisWord into StringLength if stringLength > 3 and stringLength < 7 then put ThisWord into RememberWord delete char Stringlength-3+1 to StringLength of ThisWord if the value of ThisWord is 0 then else put PartNumToString(ThisWord) & "Thousand " into Thousands end if put char StringLength-3+1 to StringLength of RememberWord into ThisWord end if put the length of ThisWord into stringLength if stringLength < 4 then if dollarPhrase is true then -- ***** USE THIS LINE TO INCLUDE THE WORD 'DOLLARS' put Millions & Thousands & PartNumToString(ThisWord) & "DOLLARS" into Dollars else -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'DOLLARS' put Millions & Thousands & PartNumToString(ThisWord) into Dollars end if end if put PartNumToString(cents) into ThisWord if ThisWord is empty then put "Zero " into ThisWord if Dollars is "Dollars" then if centPhrase is true then -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS' put ThisWord & "CENTS" into ThisWord else -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS' put ThisWord into ThisWord end if else if centPhrase is true then -- ***** USE THIS LINE TO INCLUDE THE WORD 'CENTS' put Dollars && "and" && ThisWord & "CENTS" into ThisWord else -- ***** USE THIS LINE TO LEAVE OFF THE WORD 'CENTS' put Dollars && "and" && ThisWord into ThisWord end if end if Return ThisWord end NumToString Function PartNumToString String put empty into part put String into ThisWord if the length of thisWord is 3 then if the value of ThisWord is 0 then put empty into String Return String exit PartNumToString end if put first char of ThisWord into String if the value of String is not 0 then put GetOnes(String) & "Hundred " into part end if put char 2 to 3 of ThisWord into String end if if the value of String < 20 then put part & GetOnes(String) into String else if string is not empty then put the value of string into TensString if TensString is 0 then put empty into String if TensString > 19 then put "Twenty " into String if TensString > 29 then put "Thirty " into String if TensString > 39 then put "Forty " into String if TensString > 49 then put "Fifty " into String if TensString > 59 then put "Sixty " into String if TensString > 69 then put "Seventy " into String if TensString > 79 then put "Eighty " into String if TensString > 89 then put "Ninety " into String put part & String into Part end if put last char of ThisWord into String put part & GetOnes(String) into String end if Return String end PartNumToString Function GetOnes Ones if Ones is empty then exit GetOnes if the value of Ones is 0 then put empty into Ones else if Ones is 1 then put "One " into Ones else if Ones is 2 then put "Two " into Ones else if Ones is 3 then put "Three " into Ones else if Ones is 4 then put "Four " into Ones else if Ones is 5 then put "Five " into Ones else if Ones is 6 then put "Six " into Ones else if Ones is 7 then put "Seven " into Ones else if Ones is 8 then put "Eight " into Ones else if Ones is 9 then put "Nine " into Ones else if Ones is 10 then put "Ten " into Ones else if Ones is 11 then put "Eleven " into Ones else if Ones is 12 then put "Twelve " into Ones else if Ones is 13 then put "Thirteen " into Ones else if Ones is 14 then put "Fourteen " into Ones else if Ones is 15 then put "Fifteen " into Ones else if Ones is 16 then put "Sixteen " into Ones else if Ones is 17 then put "Seventeen " into Ones else if Ones is 18 then put "Eighteen " into Ones else if Ones is 19 then put "Nineteen " into Ones Return Ones end GetOnes -- part 2 (field) -- low flags: 00 -- high flags: 4004 -- rect: left=264 top=74 right=141 bottom=509 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: -- part 3 (field) -- low flags: 01 -- high flags: 0004 -- rect: left=435 top=32 right=47 bottom=495 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 3 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: See Script ----- HyperTalk script ----- on mouseUp edit script of card button "Convert # to String" end mouseUp -- part contents for background part 8 ----- text ----- Card 11 of 20 -- part contents for card part 2 ----- text ----- 450: Four Hundred Fifty DOLLARS and Zero CENTS -- part contents for background part 9 ----- text ----- CONVERT NUMBER TO STRING This button can be very a very useful conversion button. When you click on the button, you are asked to enter a number. The number will then be converted to a string. You can set the variables DOLLARPHRASE and CENTPHRASE to false if you don't need the words DOLLARS or CENTS added to the phrase. If this script were put into the background of the card, (except for the mouseUp portion) you could convert a number to a phrase anytime simply by using NUMTOSTRING(number). Example: put NUMTOSTRING(450) into card field id 2 -- part contents for card part 3 ----- text ----- See Script